package com.laoyao.controller;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.laoyao.comm.config.CrossOrigin;
import com.laoyao.comm.model.Lunbotu;
import com.laoyao.util.DateUtil;
import com.laoyao.validate.LunbotuValidate;

@CrossOrigin
public class LunbotuController extends Controller {
	
	//两行代码搞定返回轮播图列表
	public void list(){
		String sql = "select * from v_lunbotu order by id desc";
		renderJson("list",Db.find(sql));
	}
	
	//添加轮播图
	@Before(LunbotuValidate.class)
	public void add(){
		Lunbotu l = getBean(Lunbotu.class,"");
		l.setTime(DateUtil.getTime());
		renderJson("success",l.save());
	}
	//获取轮播图数据
	public void getLunbotuById(){
		String id = getPara("id");
		renderJson("lunbotu",Lunbotu.dao.findById(id));
	}
	//修改轮播图
	@Before(LunbotuValidate.class)
	public void update(){
		Lunbotu l = getBean(Lunbotu.class,"");
		l.setTime(DateUtil.getTime());
		
		renderJson("success",l.update());
	}
	public void del(){
		Lunbotu l = getBean(Lunbotu.class,"");
		renderJson("success",l.delete());
	}
}
